package server.demo.util;

import java.security.MessageDigest;

public class TestPassword {
    
    public static String hashPassword(String password) {
        try {
            MessageDigest md = MessageDigest.getInstance("SHA-256");
            byte[] hashedBytes = md.digest(password.getBytes());
            StringBuilder sb = new StringBuilder();
            for (byte b : hashedBytes) {
                sb.append(String.format("%02x", b));
            }
            return sb.toString();
        } catch (Exception e) {
            throw new RuntimeException("密码加密失败", e);
        }
    }
    
    public static void main(String[] args) {
        String[] passwords = {"user123", "123456", "password", "admin", "user"};
        String targetHash = "564b2ea888c0c7de4e1396b86edc5ed59ca10541dfe33ee6e91a2b9c6b2b5d0f";
        
        for (String password : passwords) {
            String hash = hashPassword(password);
            System.out.println(password + " -> " + hash);
            if (hash.equals(targetHash)) {
                System.out.println("匹配！密码是：" + password);
            }
        }
    }
}